import {CHANGE_INPUT_VALUE, ADD_TODO_ITEM, DELETE_TODO_ITEM, INIT_LIST, GET_INIT_LIST} from "./actionType"

const defaultState = {
    inputValue: '',
    list: []
}
export default (state = defaultState, action) => {
    const newState = JSON.parse(JSON.stringify(state));
    switch (action.type) {
        case CHANGE_INPUT_VALUE:
            newState.inputValue = action.value;
            break
        case ADD_TODO_ITEM:
            newState.list.push(newState.inputValue)
            newState.inputValue = ''
            break
        case DELETE_TODO_ITEM:
            newState.list.splice(action.index, 1);
            break
        case GET_INIT_LIST:
            newState.list=action.list
            break
        default:
            break
    }
    return newState;
}